package com.hsmw.api.service;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.hsmw.api.config.jwt.CurrentHsmwUserUtils;
import com.hsmw.api.config.jwt.LoginUser;
import com.hsmw.api.mapper.HsmwDriverNewsMapper;
import com.hsmw.api.mapper.HsmwUserDriverMapper;
import com.hsmw.common.base.BaseService;
import com.hsmw.domain.HsmwDriverNews;
import com.hsmw.domain.HsmwRole;
import com.hsmw.domain.HsmwUser;
import com.hsmw.domain.HsmwUserDriver;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Isolation;
import org.springframework.transaction.annotation.Propagation;
import org.springframework.transaction.annotation.Transactional;

import java.util.HashMap;


/**
 * @author WD
 */
@Service
@Transactional(isolation = Isolation.REPEATABLE_READ, propagation = Propagation.REQUIRED, rollbackFor = Exception.class)
public class HsmwDriverNewsService extends BaseService<HsmwDriverNewsMapper, HsmwDriverNews> {

	@Autowired
	private HsmwDriverNewsMapper hsmwDriverNewsMapper;
	@Autowired
	private CurrentHsmwUserUtils currentHsmwUserUtils;

	public void updateAlreadyRead(HashMap param) {
		hsmwDriverNewsMapper.updateAlreadyRead(param);
	}

    public IPage<HsmwDriverNews> getHsmwNewsPage(IPage page, HsmwDriverNews hsmwDriverNews) {
		LoginUser hsmwUser = currentHsmwUserUtils.getCurrentUserInfo();
		LambdaQueryWrapper<HsmwDriverNews> queryWrapper = new LambdaQueryWrapper<>();
		queryWrapper.eq(HsmwDriverNews::getUserId,hsmwUser.getId());
		IPage ipage = this.baseMapper.selectPage(page, queryWrapper.orderByDesc(HsmwDriverNews::getCreateTime));
		return ipage;
    }
}
